﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace WPFSample.PrintEllipseSample
{
    class PrintEllipse:Window
    {
        public PrintEllipse()
        {
            this.Title = "Print Ellipse";
            this.FontSize = 24;

            StackPanel stack = new StackPanel();
            this.Content= stack;

            Button btn = new Button()
            {
                Content = "Print...",
                HorizontalAlignment = HorizontalAlignment.Center,
                Margin = new Thickness(24)
            };
            btn.Click += this.PrintOnClick;
            stack.Children.Add(btn);
        }

        private void PrintOnClick(object sender, RoutedEventArgs e)
        {
            PrintDialog dlg = new PrintDialog();
            if (dlg.ShowDialog().GetValueOrDefault())
            {
                DrawingVisual vls = new DrawingVisual();
                DrawingContext dc = vls.RenderOpen();

                dc.DrawEllipse(Brushes.LightGray, new Pen(Brushes.Black, 3),
                    new Point(dlg.PrintableAreaWidth / 2, dlg.PrintableAreaHeight / 2),
                    dlg.PrintableAreaWidth / 2,
                    dlg.PrintableAreaHeight / 2);

                dc.Close();

                dlg.PrintVisual(vls, "My frist print job");
            }
        }
    }
}
